<?php
include_once("/var/www/vhdocs/mobile/dbconnect/db.php");
Class BatchDBManager
{
   function getCid($video_id) {
        $sql = "select `cid` from `videolist` where `video_id` =$video_id";
        $result = mysql_query($sql);
        $data = mysql_fetch_row($result);
        $cid = $data[0];
        return $cid;
   }


   function getStatus($video_id,$carrier_id) {
        $sql = "select `status` from `ex_list` where `video_id` =$video_id and `carrier_id`=$carrier_id";        
        $result = mysql_query($sql);
        $data = mysql_fetch_row($result);
        $status = $data[0];
        return $status;
   }

   function insertExInfoNoExists($video_id,$carrier_id,$stutas) {
	$sql = "Insert into `ex_list`(`video_id`,`carrier_id`,`ex_date`,`status`,`last_ex_datetime`) Values( $video_id,$carrier_id,now(),$stutas,now())";
	//echo $sql;
	$count = mysql_query($sql);
	if($count>0) {
	    return 1; //"insert success!"
	} else {
	    return 0; //"insert error!"
	}   
   }

   function insertExInfoExists($video_id,$carrier_id,$part_num) {
       $sql = "Insert into `ex_list`(`video_id`,`carrier_id`,`ex_date`,`ex_cnt`,`status`,`part_num`,`last_ex_datetime`) Values( $video_id,$carrier_id,now(),1,2,$part_num,now())";
	//echo $sql;
	$count = mysql_query($sql);
	if($count>0) {
	    return 1; //"insert success!"
	} else {
	    return 0; //"insert error!"
	}   
   }
	
   function updateExInfoSuccess($video_id,$carrier_id,$part_num) {
	$sql = "update `ex_list` set `ex_date` = now(), `status`= 2 ,`ex_cnt` = `ex_cnt` + 1,`last_ex_datetime`=now(), `part_num` = $part_num  where `video_id` = $video_id and `carrier_id`=$carrier_id";
	//echo $sql;
	$count = mysql_query($sql);
	if($count>0) {
	    return 1; //"insert success!"
	} else {
	    return 0; //"insert error!"
	}   
    }
	
   function updateExInfoExists($video_id,$carrier_id) {
	$sql = "update `ex_list` set `ex_cnt` = `ex_cnt` + 1,`last_ex_datetime`=now() where `video_id` = $video_id and `carrier_id`=$carrier_id";
	//echo $sql;
	$count = mysql_query($sql);
	if($count>0) {
            return 1; //"insert success!"
	} else {
	    return 0; //"insert error!"
	}   
    }
	
	
    function updateStatus($video_id,$carrier_id,$status) {
	$sql = "update  `ex_list` set `status`=$status,`last_ex_datetime`=now() where `video_id`=$video_id and `carrier_id`=$carrier_id";
	//echo $sql;
	$count = mysql_query($sql);
	if($count>0) {
	    return 1; //"insert success!"
	} else {
	    return 0; //"insert error!"
	}   
    }
	
    function updateExcnt($video_id,$carrier_id) {
	$sql = "update  `ex_list` set `ex_cnt`=`ex_cnt` + 1,`last_ex_datetime`=now() where `video_id`=$video_id and `carrier_id`=$carrier_id";
	//echo $sql;
	$count = mysql_query($sql);
	if($count>0) {
	    return 1; //"insert success!"
	} else	{
	    return 0; //"insert error!"
	}   
    }
}

?>   
